//
//  BonusFactory.m
//  iFly
//
//  Created by User-10 on 12/7/14.
//  Copyright (c) 2014 TeamDifferent. All rights reserved.
//

#import "BonusFactory.h"
#import "CoinBonus.h"
#import "HealBonus.h"
#import "TripleLaserBonus.h"

@implementation BonusFactory

+ (BonusNode*) createBonusWithType:(BonusType)type inScene:(SKScene*) scene {
    BonusNode* bonus;
    //selecting random y position for bonus
    int r = arc4random()%((NSInteger)scene.frame.size.height - spawningRange) + spawningOffset;
    CGPoint position = CGPointMake(scene.frame.size.width,r);
    
    
    if ([BonusFactory createTripleLaserWithPosition:position ByChanceInScene:scene]) {
        return nil;
    }
    
    if ([BonusFactory createHealWithPosition:position ByChanceInScene:scene]) {
        return nil;
    }
    
    if (type == BonusTypeCoin) {
        bonus = [CoinBonus coinWithPosition:position];
    }
    [bonus move];
                                   
    return bonus;
}

+ (BOOL) createTripleLaserWithPosition:(CGPoint) position ByChanceInScene:(SKScene*)scene {
    NSInteger random = arc4random_uniform(100);
    
    if (random < chanceForTripleLaser) {
        
        TripleLaserBonus* tripleLaser = [TripleLaserBonus tripleLaserWithPosition:position];
        
        [scene addChild:tripleLaser ];
        [tripleLaser setScale:scene.size.height/sceneScaling*1.2];
        [tripleLaser move];
        
        return YES;
    }
    return NO;
}

+ (BOOL) createHealWithPosition:(CGPoint)position ByChanceInScene:(SKScene *)scene {
    NSInteger random = arc4random_uniform(100);
    
    if (random < chanceForHeal) {
        
        HealBonus* heal = [HealBonus healWithPosition:position];

        [scene addChild:heal];
        [heal setScale:scene.size.height/sceneScaling/2];
        [heal move];
        
        return YES;
    }
    return NO;
}

@end
